from PySide2.QtWidgets import QMainWindow
from PySide2.QtCore import QSize, Qt, Signal

from home import Home
from configwidget import ConfigWidget
from tool import storage, dbutil, util


class MainWindow(QMainWindow):
    
    def __init__(self):
        super(MainWindow, self).__init__()
        main_config = util.get_main_config()
        if main_config:
            success = dbutil.main()
            if success:
                self.showHomeWidget()
            else:
                self.showConfigWidget()
        else:
            self.showConfigWidget()
            

    def showConfigWidget(self):
        self.widget = ConfigWidget()
        self.widget.callback_signal.connect(self.showHomeWidget)
        self.setCentralWidget(self.widget)

    def showHomeWidget(self):
        self.widget = Home()
        self.setCentralWidget(self.widget)




